//
//  PersentAnimtion.swift
//  AppStore_Demo
//
//  Created by yangyu on 2017/10/26.
//  Copyright © 2017年 YangYiYu. All rights reserved.
//

import UIKit

class PersentAnimtion: NSObject, UIViewControllerAnimatedTransitioning {


    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 1
    }
    
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let container = transitionContext.containerView
        let to = transitionContext.view(forKey: .to)
        
        let fromController = transitionContext.viewController(forKey: .from) as! ViewController
        let toController = transitionContext.viewController(forKey: .to) as! DetailViewController
        
        let snapshotView = fromController.selectedCell.snapshotView(afterScreenUpdates: false)
        snapshotView!.frame = container.convert(fromController.selectedCell.frame, from: fromController.view)
        fromController.selectedCell.isHidden = true
        
        toController.view.frame = transitionContext.finalFrame(for: toController)
        toController.view.alpha = 0
        
        container.addSubview(toController.view)
        container.addSubview(snapshotView!)
        
        UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 4, options: .curveEaseInOut, animations: {
            
        }) { (complete) in
            
        }
        
        
    }
    
}
